#pragma once

#include <gl/glew.h>
#include "TextureUnit.h"
#include "ICleanableObserver.h"
#include "Texture2DGL3x.h"
#include "TextureSamplerGL3x.h"


namespace Renderer
{
	namespace GL3x
	{
		class TextureUnitGL3x : public TextureUnit, public ICleanable
		{
		public:

			TextureUnitGL3x(int index, ICleanableObserver* observer);

			Texture2D* GetTexture() const;

			void SetTexture(Texture2D* t);

			Renderer::TextureSampler* GetTextureSampler() const;

			void SetTextureSampler(Renderer::TextureSampler* ts);

			void CleanLastTextureUnit();
			
			void Clean() override;

		private:
			void Validate();

			enum DirtyFlags
			{
				None = 0,
				Texture = 1,
				TextureSampler = 2,
				All = Texture | TextureSampler
			};
		private:
			int _textureUnitIndex;
			GLuint _textureUnit;
			ICleanableObserver* _observer;
			Texture2DGL3x* _texture;
			TextureSamplerGL3x* _textureSampler;
			DirtyFlags _dirtyFlags;
		};
	}
}
